package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseUser;
import com.briup.mt.bean.Interfaces;
import com.briup.mt.bean.InterfacesExample;
import com.briup.mt.dao.InterfacesMapper;
import com.briup.mt.service.IBaseUserService;
import com.briup.mt.service.IInterfacesService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class InterfacesImpl implements IInterfacesService {
    @Resource
    private InterfacesMapper interfacesMapper;

    @Override
    public List<Interfaces> query(String iname, String userName) {
        InterfacesExample example = new InterfacesExample();
        if(!StringUtils.isEmpty(iname)){
            example.createCriteria().andNameLike("%"+ iname +"%");
        }
        if (!StringUtils.isEmpty(userName)){
            example.createCriteria().andUserNameLike("%" + userName + "%");
        }
        List<Interfaces> list = interfacesMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Interfaces interfaces) {
        Long id = interfaces.getId();
        if (interfacesMapper.selectByPrimaryKey(id) == null){
            interfaces.setStatus("正常");
            interfacesMapper.insert(interfaces);
        }else {
            interfacesMapper.updateByPrimaryKey(interfaces);
        }
    }

    @Override
    public void deleteById(Long id) {
        interfacesMapper.deleteByPrimaryKey(id);

    }
}
